<template>
  <page-header-wrapper>
    <template v-slot:content> 所属楼盘：{{ $route.query.name }} </template>
    <global-search :list="searchList" @search="handleSearch" @reset="handleReset"> </global-search>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }">
        <template #tabAction>
          <y-button type="primary" icon="plus" @click="handleAdd">新建房源</y-button>
        </template>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" size="small" @click="handleHouseList(record)"> 查看 </y-button>
          <y-button type="link" size="small" @click="handleFloorList(record)"> 查看总楼层 </y-button>
          <a-dropdown :trigger="['click']">
            <span class="text-primary m-l-10">
              更多
              <a-icon type="down" />
            </span>
            <a-menu slot="overlay" @click="handleMenuClick($event, record)">
              <a-menu-item key="visibleBatch">
                <span>调整</span>
              </a-menu-item>
              <a-menu-item key="visibleTable">
                <span>查看列表</span>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </div>
      </s-table>
    </a-card>
    <house-form :visible.sync="visibleForm" @success="tableRefresh"/>
    <house-list :visible.sync="visibleHouseList" :data.sync="realEstate" />
    <floor-list :visible.sync="visibleFloorList" :data.sync="realEstate" />
    <batchEdit :visible.sync="visibleBatch" :data.sync="realEstate" />
    <houseTable :visible.sync="visibleTable" :data.sync="realEstate" />
  </page-header-wrapper>
</template>

  <script>
import { STable, Ellipsis } from '@/components'
import houseForm from './components/houseForm.vue'
import houseList from './components/houseList.vue'
import floorList from './components/floorList.vue'
import batchEdit from './components/batchEdit.vue'
import houseTable from './components/houseTable.vue'
import { getHouseInfoList } from '@/api/followUpManagement'
export default {
  components: {
    STable,
    Ellipsis,
    houseForm,
    houseList,
    floorList,
    batchEdit,
    houseTable
  },
  data () {
    return {
      visibleHouseList: false,
      visibleFloorList: false,
      visibleForm: false,
      visibleBatch: false,
      visibleTable: false,
      realEstate: {},
       queryParam: {
        ID: this.$route.params.id,
        strContent: {}
      },
      searchList: [
        {
          label: '查找房源',
          fields: 'Roof',
          type: 'input',
          extra: '支持模糊搜索',
          props: {
            placeholder: '请输入栋号'
          }
        }
      ],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' }
        },
        {
          title: '栋',
          align: 'center',
          dataIndex: 'Roof',
          sorter: (a, b) => a.Roof.localeCompare(b.Roof)
        },
        {
          title: '单元',
          align: 'center',
          dataIndex: 'Unit',
          sorter: (a, b) => a.Unit - b.Unit
        },
        {
          title: '起始楼层',
          align: 'center',
          dataIndex: 'StartFloor',
          sorter: (a, b) => a.StartFloor - b.StartFloor
        },
        {
          title: '总楼层',
          align: 'center',
          dataIndex: 'TotalFloor',
          sorter: (a, b) => a.TotalFloor - b.TotalFloor
        },
        {
          title: '总面积（㎡）',
          align: 'center',
          dataIndex: 'TotalArea',
          sorter: (a, b) => a.TotalArea - b.TotalArea
        },
        {
          title: '操作',
          align: 'center',
          width: '210px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        this.selectedRowKeys = []
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getHouseInfoList(requestParameters).then((res) => res)
      }
    }
  },
  methods: {
    handleSearch (values) {
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset () {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh (refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleMenuClick (e, record) {
      const { key } = e
      this.realEstate = record
      this[key] = true
    },
    handleAdd () {
      this.realEstate = {}
      this.visibleForm = true
    },
    handleHouseList (e) {
      this.realEstate = e
      this.visibleHouseList = true
    },
    handleFloorList (e) {
      this.realEstate = e
      this.visibleFloorList = true
    }
  }
}
</script>
  <style scoped>
</style>
